<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p span{
            background-color: red;
        }
    </style>
</head>
<body>
    <p id="p1">希望开学希望下课</p>
    <script>
        // var strTest='ababcc'
        // var intPos=strTest.indexOf('a',0)
        // console.log(intPos)
        // var strTest='13718884563'
        // var reg=/8/g
        // var blnresult=reg.test(strTest)
        // console.log(blnresult)
        // var arrNewTest=strTest.match(reg)
        // console.log(strTest)
        // var newString=strTest.replace(reg,'*')
        // console.log(newString)
        var str='希望'
        var reg=new RegExp(str,'g')
        var oldStr=document.getElementById('p1').innerText
        var newStr=oldStr.replace(reg,'<span>'+str+'</span>')
        document.getElementById('p1').innerHTML=newStr
    </script>
</body>
</html>